
#include "ftpget.h"


int main(int argc, char *argv[]) {
	int i;
	char login[MAX_AUTH], pass[MAX_AUTH], hostname[MAX_PATH], url_path[MAX_PATH];

	if (argc < 2) {
		printf("Usage: %s ftp://[<user>:<password>@]<host>/<url-path> ...\n",argv[0]);
		exit(0);
	}

//	//DEBUG
//	for (i = 0; i < argc; i++) {
//		printf("argv[%d]: [%s]\n", i, argv[i]);
//	}

	for (i = 1; i < argc; i++) {

		if (strchr(argv[i], '@') != NULL) { // conexão com autenticação
			sscanf(argv[i], "ftp://%[^:]:%[^@]@%[^/]/%[^\n]", login, pass,
					hostname, url_path);
		} else { // conexão anônima
			sscanf(argv[i], "ftp://%[^/]/%[^\n]", hostname, url_path);
			strcpy(login, "anonymous");
			strcpy(pass, "anonymous");
		}

		//DEBUG
		printf("Session %d:\n",i);
		printf("host: %s\n",hostname);
		printf("url-path: %s\n",url_path);
		printf("login: %s\n",login);
		printf("password: %s\n\n",pass);

		ftpget(hostname, url_path, login, pass);
	}

	return 0;
}
